<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar title="商品评价" bgColor="#F5F5F5" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		
		
		<view v-if="list.length > 0">
			<view class="flex-col com-content" v-for="(re,ri) in list" :key="ri">
					<view class="flex-row" style="margin-top: 40rpx;">
						<image :src="re.avatar ? re.avatar : staticResource('user/default_avatar.jpg')" style="width: 80rpx;height: 80rpx;border-radius: 40rpx;"></image>
					
						<view class="flex-col" style="margin-left: 25rpx;width: 90%;">
							<text>{{re.nickname}}</text>
							<view>
								<u-rate active-color="#5c8edc" inactive-color="#b2b2b2" :value="re.star" readonly gutter="3"></u-rate>
							</view>
							<text style="margin-top: 20rpx;margin-right: 40rpx;">{{re.comment}}</text>
							
							<view v-if="re.img_url">
								<image class='img_wrap_one' :src="re.img_url" @click="clickImg(re.img_url)"  style="margin-top: 10rpx;border-radius: 5rpx;"/>
							</view>
							<view v-else></view>
							
							<view style="color: #555;font-size: 23rpx;margin-top: 10rpx;">{{re.create_date}}</view>
						</view>
					</view>
			</view>
		</view>
		<view v-else class="flex-col items-center" style="margin-top: 80rpx;">
			<image src="/static/data_empty.png"></image>
			<text style="color: #c0c4cc;">暂无数据</text>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
				goods_id:''
			};
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight +44;
			}
		},
		onLoad(op) {
			this.goods_id = op.goods_id;
		},
		onShow() {
			this.list = [];
			this.page = 1;
			this.getCommentList();
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.getCommentList();
		},
		onReachBottom() {
			this.getCommentList();
		},
		methods:{
			clickImg(url){
				uni.previewImage({
					urls:[url]
				});
			},
			getCommentList(){
				this.$request({
					url:'?c=Goods&a=goodsAllComments',
					type:'post',
					data:{
						goods_id:this.goods_id,
						page:this.page,
						limit:10
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.info.length > 0) {
						this.list = [...this.list, ...res.data.info];
						this.page += 1;
						if (res.data.info.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
				});
			},
			staticResource(path){
				return "https://ysmz.scmzhc.com/static/mini/images/"+path;
			}
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
	background-color: #F5F5F5;
}
.img_wrap_one {
	height: 200rpx;
	width: 180rpx;
}
.com-content{
	background-color: #fff;
	margin: 20rpx;
	border-radius: 10rpx;
	padding: 20rpx;
}
</style>
